﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.Execution;
using Microsoft.VisualStudio.TestTools.Common;

namespace NUnitForVSTS.NUnitTest.UT
{
    [Serializable]
    public class DummyResultSink : IResultSink
    {
        public DummyResultSink()
        {
            Result = new StringBuilder();
            TestMessages = new List<TestResultMessage>();
        }

        public StringBuilder Result { get; set; }
        public List<TestResultMessage> TestMessages { get; set; }

        #region IResultSink Members

        public void AddResult(TestMessage testMessage)
        {
            
            Result.AppendLine("Valid:" + testMessage.IsValid().ToString());
            Result.AppendLine(testMessage.ToString());
            TestResultMessage resultMessage = testMessage as TestResultMessage;
            if (resultMessage != null)
            {
                TestMessages.Add(resultMessage);
                if (resultMessage.SystemException != null)
                {
                    Result.AppendLine("ExceptionMessage:" + resultMessage.SystemException.Message);
                    Result.AppendLine("ExceptionStackTrace:" + resultMessage.SystemException.StackTrace);
                }
            }
            RunOutputTestResultMessage result = testMessage as RunOutputTestResultMessage;
            if (result != null)
            {
                Result.AppendLine("ComputerName:" + result.ComputerName);
                Result.AppendLine("STDERR:" + result.StdErr);
                Result.AppendLine("STDOUT:" + result.StdOut);
            }
        }

        #endregion
    }
}
